﻿import QtQuick 2.0
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Window 2.12
import QtQuick.Controls.Styles 1.4

import "../components"
// 定义弹窗
Window {
    id: root
    title: "上传文件"

    maximumHeight: 450*dp
    minimumHeight: 450*dp
    maximumWidth: 600*dp
    minimumWidth: 600*dp

    // 假设的数据源，用于映射每行的ComboBox选项
    property var comboBoxData: CULF.allnames()
    property var comboBoxDatac: CULF.allvolumes()

    signal accept()
    signal reject()

    modality: Qt.WindowModal
    flags: Qt.Window | Qt.WindowTitleHint |Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint

    Column{
        x: 20*dp
        y: 20*dp
        // 文件选择
        Row {
            spacing: 10*dp // 设置 Row 内部子项之间的间距
            CustomComboBox{
                id: dlyqwj
                title: "定量仪器文件"
                model: filetype
                textWidth: 100*dp
                editWidth: 130*dp
                onCurrentText: {
                    CULF.fileTypeChange(text)
                }
            }
            LineEditor{
                id: edit_file
                title: "文件路径"
                editable: false
                textWidth: 70*dp
                editWidth: 130*dp
            }
            PushButton{
                title: "选择文件"
                button_icon: "qrc:/picture/iconXZ.png"
                defaultMode2: true
                width: 110*dp
                onReleased: {
                    edit_file.setText(CULF.fileChoose())
                }
            }
        }
        Item{ height: 20*dp; width: 20*dp }      // 占位行 =========
        CustomComboBox{
            title: "基因分析仪"
            model: jyfxytype
            textWidth: 100*dp
            editWidth: root.width - textWidth - 40*dp
            onCurrentText: {

            }
        }
        Item{ height: 20*dp; width: 20*dp }      // 占位行 =========
        // 自定义表头
        Rectangle {
            width: root.width-40*dp
            height: 50*dp
            color: "#f0f0f0"
            border.color: "#ccc"

            // 表头内容
            Row{
                anchors.fill: parent
                Item{
                    height: parent.height; width: 80*dp
                    CheckBox {
                        id: selectAllCheckbox
                        anchors.centerIn: parent
                        onClicked: {
                            // 更新所有行的复选框状态
                            for (let i = 0; i < tableModel.count; i++) {
                                tableModel.get(i).checked = selectAllCheckbox.checked; // 设置checked属性
                                tableModel.set(i, tableModel.get(i)); // 更新模型数据
                            }
                        }
                    }
                }
                Item{
                    height: parent.height; width: 120*dp
                    Text{
                        text: "试剂盒类型"
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Item{
                    height: parent.height; width: root.width-40*dp-300*dp
                    Text{
                        text: "试剂盒名称"
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }Item{
                    height: parent.height; width: 100*dp
                    Text{
                        text: "体系(μl)"
                        font.pixelSize: config.fontsize
                        anchors.centerIn: parent
                    }
                }
            }
        }

        // 使用 ListView 模拟表格
        ListView {
            id: tableView
            width: root.width - 40*dp
            height: 300*dp
            anchors.horizontalCenter: parent.horizontalCenter
            interactive: false

            model: ListModel {
                id: tableModel
                ListElement { checked: false; type: "常STR"; nameIndex: 0; volumeIndex: 0; }
                ListElement { checked: false; type: "Y-STR"; nameIndex: 1; volumeIndex: 1; }
                ListElement { checked: false; type: "mini-STR"; nameIndex: 2; volumeIndex: 2; }
            }

            delegate: Rectangle {
                width: root.width-40*dp
                height: 50*dp

                Row{
                    anchors.fill: parent
                    Rectangle{      // 复选框
                        color: "#CCCCCC"
                        Rectangle{ height: parent.height-1; width: parent.width-2; x: 1 }   // 边框
                        height: parent.height; width: 80*dp
                        CheckBox {
                            checked: model.checked
                            anchors.centerIn: parent
                            onCheckedChanged: {
                                model.checked = checked
                                if(checked){
                                    CULF.isched(index,1);
                                }else{
                                    CULF.isched(index,0);
                                }

                                // 检查所有复选框的状态来更新全选复选框
    //                            let allChecked = true;
    //                            for (let i = 0; i < tableModel.count; i++) {
    //                                if (!tableModel.get(i).checked) {
    //                                    allChecked = false;
    //                                    break;
    //                                }
    //                            }
    //                            selectAllCheckbox.checked = allChecked; // 更新全选复选框状态
                            }
                        }
                    }Rectangle{     // 试剂盒类型-Text
                        color: "#CCCCCC"
                        Rectangle{ height: parent.height-1; width: parent.width-1 }   // 边框
                        height: parent.height; width: 120*dp
                        Text {
                            text: model.type
                            font.pixelSize: config.fontsize
                            anchors.centerIn: parent
                        }
                    }Rectangle{     // 试剂盒名称-ComboBox
                        color: "#CCCCCC"
                        Rectangle{ height: parent.height-1; width: parent.width-1 }   // 边框
                        height: parent.height; width: root.width-40*dp-300*dp
                        CustomComboBox{
                            anchors.centerIn: parent
                            model: comboBoxData[index]
                            editWidth: parent.width - 5
                            comboCurrentIndex: model.nameIndex
                            comboFontHorAlign: Text.AlignHCenter
                            comboBorderWidth: 0
                            onCurrentText: {
                                model.nameIndex = getIndex()
                                CULF.isname(index, getText())
                            }
                        }
                    }Rectangle{     // 体系-ComboBox
                        color: "#CCCCCC"
                        Rectangle{ height: parent.height-1; width: parent.width-1 }   // 边框
                        height: parent.height; width: 100*dp
                        CustomComboBox{
                            anchors.centerIn: parent
                            model: comboBoxDatac[index]
                            editWidth: parent.width - 5
                            comboCurrentIndex: model.nameIndex
                            comboFontHorAlign: Text.AlignHCenter
                            comboBorderWidth: 0
                            onCurrentText: {
                                model.nameIndex = getIndex()
                                CULF.isvolume(index, getText())
                            }
                        }
                    }
                }
            }

            ScrollBar.vertical: ScrollBar{}
        }
    }

    Item{
        height: 40*dp
        width: root.width
        y: root.height - 80*dp
        PushButton{
            title: "取消"
            x: root.width / 2 - 130*dp
            defaultMode2: true
            onReleased: {
                root.reject()
                root.close()
            }
        }PushButton{
            title: "分析"
            x: root.width / 2 + 10*dp
            defaultMode1: true
            onReleased: {
                root.accept()
            }
        }
    }

}
